package org.example.config;

import org.example.interceptor.ApiIdempotentInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author shenguangyang
 */
@Configuration
public class ApiIdempotentWebConfig implements WebMvcConfigurer {
    private static final Logger log = LoggerFactory.getLogger(ApiIdempotentWebConfig.class);

    @Resource
    private ApiIdempotentInterceptor appInterceptor;

    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("registry interceptor: {}", appInterceptor.getClass().getName());
        registry.addInterceptor(appInterceptor).addPathPatterns("/**");
    }
}
